#include <iostream>
using namespace std;

int arr[1005][1005];

int main()
{
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			cin >> arr[i][j];
		}
	}
	
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			if(arr[i-1][j] < arr[i][j-1])
			{
				arr[i][j] += arr[i][j-1];
			}
			else
			{
				arr[i][j] += arr[i-1][j];
			}
		}	
	}	
	
	cout << arr[n][m] << endl;
	return 0;
}
